//
//  ConfirmationBetViewController.m
//  PlayerWorld
//
//  Created by 1 on 16/5/16.
//  Copyright © 2016年 刘成. All rights reserved.
//
#define UISCREEN_WIDTH  [UIScreen mainScreen].bounds.size.width
#define UISCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#import "ConfirmationBetViewController.h"
#import "BettingRecordViewController.h"
#import "ProcurementHallViewController.h"
#import "UIKit+AFNetworking.h"
@interface ConfirmationBetViewController ()

@end

@implementation ConfirmationBetViewController
{
    UILabel *ConfirmationbetLabel3;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"投注成功";
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    UIImageView *ConfirmationbetImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 130, 50, 50)];
    
    ConfirmationbetImageView.image = [UIImage imageNamed:@"icon_chest"];
    
    [self.view addSubview:ConfirmationbetImageView];
    
    UILabel *ConfirmationbetLabel = [[UILabel alloc]initWithFrame:CGRectMake(120, 150, 150, 20)];
    ConfirmationbetLabel.text = @"恭喜您，购彩成功!";
    ConfirmationbetLabel.font = [UIFont systemFontOfSize:16];
    
    [self.view addSubview:ConfirmationbetLabel];
    
    UIImageView *ConfirmationbetImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(ConfirmationbetImageView.frame), UISCREEN_WIDTH, 1)];
    
    ConfirmationbetImageView2.image = [UIImage imageNamed:@"betting_line"];
    
    [self.view addSubview:ConfirmationbetImageView2];
    
    UIImageView *ConfirmationbetImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake(50, CGRectGetMaxY(ConfirmationbetImageView2.frame)+20, 50, 50)];
    
    ConfirmationbetImageView3.image = [UIImage imageNamed:@"icon_money_2"];
    
    [self.view addSubview:ConfirmationbetImageView3];
    
    UILabel *ConfirmationbetLabel2 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(ConfirmationbetImageView3.frame)+20, CGRectGetMaxY(ConfirmationbetImageView.frame)+20, 200, 20)];
    ConfirmationbetLabel2.text = [NSString stringWithFormat:@"本次投注金额：%@.00元",self.money];
    ConfirmationbetLabel2.font = [UIFont systemFontOfSize:14];
    ConfirmationbetLabel2.textColor = [UIColor grayColor];
    [self.view addSubview:ConfirmationbetLabel2];
    
    ConfirmationbetLabel3 = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(ConfirmationbetImageView3.frame)+20, CGRectGetMaxY(ConfirmationbetImageView.frame)+50, 200, 20)];
    [self obtainData];
//    ConfirmationbetLabel3.text = @"账户余额：524525.5元";
    ConfirmationbetLabel3.font = [UIFont systemFontOfSize:14];
    ConfirmationbetLabel3.textColor = [UIColor grayColor];
    [self.view addSubview:ConfirmationbetLabel3];

    UIButton *ConfirmationbetButton = [[UIButton alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(ConfirmationbetImageView3.frame)+20, (UISCREEN_WIDTH-20-20-20)/2, 30)];
    [ConfirmationbetButton setTitle:@"投注记录" forState:UIControlStateNormal];
    [ConfirmationbetButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    ConfirmationbetButton.backgroundColor = [UIColor colorWithRed:46/255.0f green:168/255.0f blue:289/255.0f alpha:1];
    [ConfirmationbetButton addTarget:self action:@selector(confirmationbetButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    ConfirmationbetButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:ConfirmationbetButton];
    
    UIButton *ConfirmationbetButton2 = [[UIButton alloc]initWithFrame:CGRectMake(20+ConfirmationbetButton.frame.size.width+20, CGRectGetMaxY(ConfirmationbetImageView3.frame)+20, (UISCREEN_WIDTH-20-20-20)/2, 30)];
    [ConfirmationbetButton2 setTitle:@"继续购彩" forState:UIControlStateNormal];
    [ConfirmationbetButton2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    ConfirmationbetButton2.backgroundColor = [UIColor colorWithRed:46/255.0f green:168/255.0f blue:289/255.0f alpha:1];
    [ConfirmationbetButton2 addTarget:self action:@selector(ConfirmationbetButton2Action:) forControlEvents:UIControlEventTouchUpInside];
    ConfirmationbetButton2.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:ConfirmationbetButton2];

}
-(void)obtainData
{
    // 启动系统风火轮
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
    
    //服务器给的域名
    NSString *domainStr = @"http://666.lefun6.com/";
    
    //创建一个可变字典
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    //往字典里面添加需要提交的参数
    [parametersDic setObject:@"User" forKey:@"Model"];
    [parametersDic setObject:@"GetUserInfo" forKey:@"Action"];
    [parametersDic setObject:@"yes" forKey:@"r"];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    //以post的形式提交，POST的参数就是上面的域名，parameters的参数是一个字典类型，将上面的字典作为它的参数
    [manager POST:domainStr parameters:parametersDic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 解析成功隐藏系统风火轮
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        //        NSLog(@"123%@",[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil]);
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        ConfirmationbetLabel3.text = [NSString stringWithFormat:@"账户余额：%@元",[[dic objectForKey:@"userinfo"] objectForKey:@"U_Money"]];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        // 解析失败隐藏系统风火轮(可以打印error.userInfo查看错误信息)
        [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
        
    }];
    
}
- (void)confirmationbetButtonAction:(UIButton *)sender {
    
    BettingRecordViewController *bRVC= [[BettingRecordViewController alloc] init];
    [self.navigationController pushViewController:bRVC animated:YES];
    
}

- (void)ConfirmationbetButton2Action:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:YES];
//    ProcurementHallViewController *pHVC= [[ProcurementHallViewController alloc] init];
//    [self.navigationController pushViewController:pHVC animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
